using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using Evolution.Engine.Managers;
using Microsoft.Xna.Framework;
using Evolution.Engine.GUI.Components;

namespace Evolution.Engine.Utilities
{
    public static class GameUtils
    {
        public static string ExecutingDirectory
        {
            get
            {
                FileInfo f = new FileInfo(Assembly.GetExecutingAssembly().Location);
                return f.Directory + "\\";
            }
        }

        public static string RelativeFileNameWithoutExtention(string fileName)
        {
            if (fileName.Contains("."))
                return fileName.Remove(0, ExecutingDirectory.Length).Split('.')[0];
            else
                return fileName;
        }

        public static string FileNameOnlyWithoutExtention(string FileName)
        {
            FileInfo f = new FileInfo(FileName);
            return f.Name.Replace(f.Extension, "");
        }

        public static string FileWithoutExtention(string FileName)
        {
            return FileName.Replace(".xnb", "");
        }

        public static string ContentFileWithoutExtention(string FileName)
        {
            string[] sections = FileName.Split(new char[] { '\\', '/' });
            string retVal = "";
            bool found = false;

            foreach (string section in sections)
            {
                if (section == "Content" || found)
                {
                    retVal += section + "/";
                    found = true;
                }
            }

            return FileWithoutExtention(retVal.Substring(0, retVal.Length - 1));
        }

        public static void AddObject(BaseObject obj)
        {
            SceneManager.Instance.AddObject(obj);
        }

        public static Target Clamp<Target>(Target scrollvalue, Target min, Target max)
        {
            return Convert.ToDouble(scrollvalue) <= Convert.ToDouble(min) 
                ? min : 
                    Convert.ToDouble(scrollvalue) >= Convert.ToDouble(max) 
                        ? max : scrollvalue;
        }

        public static Point ConvertToPoint(Vector2 pos)
        {
            return new Point((int)pos.X, (int)pos.Y);
        }

        public static Vector2 ConvertToVector(Point pos)
        {
            return new Vector2(pos.X, pos.Y);
        }

        public static Vector2 ConvertToVector(SizeF size)
        {
            return new Vector2(size.Width, size.Height);
        }
    }
}
